<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        li {
            list-style: none;
        }

        #div1 {
            width: 540px;
            height: 540px;
            margin: 50px auto;
            overflow: hidden;
            position: relative;
        }

        #div1 ul {
            position: absolute;
            left: 0;
            top: 0;
        }

        #div1 ul.trans {
            transition: top 1s;
        }

        #div1 ul li {
            height: 540px;
        }

        #div1 ol {
            position: absolute;
            right: 10%;
            bottom: 10px;
            z-index: 6
        }

        #div1 ol li {
            width: 20px;
            height: 20px;
            background: #fff;
            margin-left: 5px;
            line-height: 20px;
            text-align: center;
            cursor: pointer;
            float: left;
        }

        #div1 ol li.ac {
            background: red;
            color: #fff;
        }

        #div1>a {
            text-decoration: none;
            position: absolute;
            top: 50%;
            margin-top: -10px;
            height: 40px;
            line-height: 32px;
            text-align: center;
            width: 40px;
            font-size: 40px;
            vertical-align: middle;
            color: #fff;
            background: rgba(0, 0, 0, 0.5);
            z-index: 6;
        }

        #goPrev {
            left: 0;
        }

        #goNext {
            right: 0;
        }

        img {
            width: 540px;
            height: 540px;
        }
    </style>
</head>

<body>
    <div id="div1">
        <ul class="trans">
            <li><a href="javascript:alert(0);"><img src="4.jpg" /></a></li>
            <li><a href="javascript:alert(1);"><img src="5.jpg" /></a></li>
            <li><a href="javascript:alert(2);"><img src="1.jpg" /></a></li>
            <li><a href="javascript:alert(3);"><img src="2.jpg" /></a></li>
            <li><a href="javascript:alert(4);"><img src="3.jpg" /></a></li>
        </ul>
        <ol>
            <li class="ac">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ol>
        <a href="javascript:;" id="goPrev">&laquo;</a>
        <a href="javascript:;" id="goNext">&raquo;</a>
    </div>
    <script>
        var div = document.querySelector('#div1')
        var ul = div.querySelector('ul')
        var btns = div.querySelectorAll('ol li')
        var goPrev = document.querySelector('#goPrev')
        var goNext = document.querySelector('#goNext')
        var liHeight = ul.children[0].offsetHeight;
        var len = ul.children.length 
        var index = 0;
        var lastIndex = 0;
        ul.appendChild(ul.children[0].cloneNode(true))
        ul.style.height=liHeight * (len + 1) + 'px'

        Array.from(btns).forEach((btn, i) => {
            btn.onclick = function () {
                lastIndex = index
                index = i
                btns[lastIndex].classList.remove('ac')
                btns[index].classList.add('ac')
                ul.style.top = -index * liHeight + 'px'
            }
        })

        goNext.onclick = function () {
            lastIndex = index
            index++
            if (index === len) {
                index = 0
                ul.style.top = -len * liHeight + 'px'
                setTimeout(() => {
                    ul.classList.remove('trans')
                    ul.style.top = '0px'
                    setTimeout(() => {
                        ul.classList.add('trans')
                    }, 100)
                }, 1000)
            } else {
                ul.style.top = -index * liHeight + 'px'
            }
            btns[lastIndex].classList.remove('ac')
            btns[index].classList.add('ac')
        }

        goPrev.onclick = function () {
            lastIndex = index;
            index--
            if (index < 0) {
                index = len - 1
                ul.classList.remove('trans')
                ul.style.top = -len * liHeight + 'px'
                setTimeout(() => {
                    ul.classList.add('trans')
                    ul.style.top = -index * liHeight + 'px'
                }, 10)
            } else {
                ul.style.top = -index * liHeight + 'px'
            }
            btns[lastIndex].classList.remove('ac')
            btns[index].classList.add('ac')
        }

        var timer = setInterval(() => {
            goNext.onclick()
        }, 2000)

        div.onmouseenter = function () {
            clearInterval(timer)
        }

        div.onmouseleave = function () {
            timer = setInterval(() => {
                goNext.onclick()
            }, 2000)
        }
    </script>
</body>

</html>